import React from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import { LocaleProvider } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';

import { getUserRoute } from './module'
import { getUserPermission } from './permission'


// const RouteWithSubRoutes = (route: IRouter) => (
// 	<Route
// 		path={route.path}
// 		render={props => (
// 			// pass the sub-routes down to keep nesting
// 			<route.component {...props} routes={route.routes} />
// 		)}
// 	/>
// );

export const renderRouter = () => {
	const routes = getUserRoute(getUserPermission());
	console.log('routes', routes)
	return (<LocaleProvider locale={zhCN}>
		<BrowserRouter>
			<Switch>
				{
					routes.map((route, i) =>
						<Route
							exact={true}
							key={route.path}
							{...route} />)
				}
			</Switch>
		</BrowserRouter>
	</LocaleProvider>)

}
